function aclCheck(doc,req) {
	print(new ISODate()+"======================start=====================");
	eval("var _req = "+req);

	var code = _req.code;
	var user = _req.user;
	var role = _req.rolelike;
	var owner;
	if( doc.owner != undefined){
		owner = doc.owner;
	}else{
		owner = doc._caccount.userid;
	}


	var dirToUser = new Array(); 
	var dirToRoleLike = new Array();
	var indirToUser  = new Array();
	var indirToRoleLike  = new Array();
	
	for (var i = 0; i < doc.acl.length; i++) {
		var item = doc.acl[i];
		print(item._id);
		if (item.valid == false) {
			continue;
		}
		
		if (item.actioncode != code) {
			continue;
		}
	
		var now = new ISODate().getTime();
		if (item.effectivefrom != undefined
				&& now < item.effectivefrom.getTime()) {
			continue;
		}
		if (item.effectiveto != undefined && now < item.effectiveto.getTime()) {
			continue;
		}
	
		if (item.visitor == "owner" && owner != user) {
			continue;
		}

        if(item.visitortype == "user" && item.visitor != user){
			continue;
		}

		if (item.visitortype == "org" || item.visitortype == "orgrole"
				|| item.visitortype == "pjrole"||item.visitortype == "team") {
							print(">>>"+item.visitor);
			var contains = false;
			if(role != "" && role != undefined ){
				for(var j =0;j<role.length;j++){
					if(role[j] == item.visitor){
						contains = true;
						break;
					}
				}
			}
			if(!contains){
				continue;
			}
		}

        if(item.permission == "r"){
        	return false;
        }
 
		var direct = item.receivedfrom != undefined;
		if ("user" == item.visitortype && user == item.visitor) {
			if (direct) {
				dirToUser.push(item.permission);
			} else {
				indirToUser.push(item.permission);
			}
		} else {
			if (direct) {
				dirToRoleLike.push(item.permission);
			} else {
				indirToRoleLike.push(item.permission);
			}
		}
	}
		

	if (dirToUser.length ==0 && indirToUser.length ==0
			&& dirToRoleLike.length ==0 && indirToRoleLike.length ==0) {
		return false;
	}

	for (var i = 0; i < dirToUser.length; i++) {
		if ("d" == dirToUser[i]) {
			return false;
		} else if ("a" == dirToUser[i]) {
			return true;
		}
	}

	for (var i = 0; i < dirToRoleLike.length; i++) {
		if ("d" == dirToRoleLike[i]) {
			return false;
		} else if ("a" == dirToRoleLike[i]) {
			return true;
		}
	}

	for (var i = 0; i < indirToUser.length; i++) {
		if ("d" == indirToUser[i]) {
			return false;
		} else if ("a" == indirToUser[i]) {
			return true;
		}
	}

	for (var i = 0; i < indirToRoleLike.length; i++) {
		if ("d" == indirToRoleLike[i]) {
			return false;
		} else if ("a" == indirToRoleLike[i]) {
			return true;
		}
	}


	return false;
}